let { bannerModel } = require("./models/bannerModel");

module.exports.addBanner = async (data) => {
    let res = await bannerModel.create(data);
    return res;
};
module.exports.searchBanner = async ({
    bannerName = "",
    pageSize = 10,
    pageIndex = 1,
}) => {
    let res = await bannerModel
        .find({ bannerName: { $regex: bannerName, $options: "$i" } })
        .limit(pageSize - 0)
        .skip((pageIndex - 1) * (pageSize - 0));
    let totalNum = await bannerModel.countDocuments({
        bannerName: { $regex: bannerName, $options: "$i" },
    });
    return { result: [...res], totalNum };
};
module.exports.updateBanner = async ({_id,...rest}) => {
    let res = await bannerModel.updateOne({_id},{...rest});
    return res;
};
module.exports.deleteBanner=async(data)=>{
    let res=await bannerModel.deleteOne(data)
    return res
}